﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace WindowsFormsApp2
{
    class ConnectData 
    {
        private static string conString;

        public static DataTable GetDataTable(string sql)
        {
            //连接数据库
            string conString = "server=.;database=vsTest;uid=sa;pwd=123456;";


            SqlConnection connection = new SqlConnection(conString);

            SqlDataAdapter adapter = new SqlDataAdapter(sql, connection);

            connection.Open();

            DataTable dt = new DataTable();
            adapter.Fill(dt);

            return dt;

        }

        public static int AddOrUpadte(string sql)
        {
            string conString = "server=.;database=vsTest;uid=sa;pwd=123456;";

            SqlConnection connection = new SqlConnection(conString);

            SqlCommand command = new SqlCommand(sql, connection);

            connection.Open();

            return command.ExecuteNonQuery();
        }
    }
}
